package com.breeze.components.message.secure.record;

import com.breeze.components.message.secure.SecureInvokeService;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import java.time.LocalDateTime;
import java.util.List;
import org.springframework.stereotype.Component;

/**
 * 本地消息记录表
 *
 * @author breeze
 * @since 2023-11-12 12:05:28
 */
@Component
public class SecureInvokeRecordService
    extends ServiceImpl<SecureInvokeRecordMapper, SecureInvokeRecord> {

  public List<SecureInvokeRecord> getWaitRetryRecords() {
    // 查10s前的失败数据 避免刚入库的数据被查出来
    LocalDateTime afterTime =
        LocalDateTime.now().minusSeconds(SecureInvokeService.RETRY_INTERVAL_SECOND);
    return queryChain()
        .eq(SecureInvokeRecord::getStatus, SecureInvokeRecord.STATUS_WAIT)
        .lt(SecureInvokeRecord::getNextRetryTime, LocalDateTime.now())
        .lt(SecureInvokeRecord::getCreateTime, afterTime)
        .list();
  }
}
